package com.spring.framework.transaction.example;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @author xuweizhi
 */
@Configuration
@SuppressWarnings("all")
@EnableTransactionManagement
@ComponentScan(basePackages = {"com.spring.framework.transaction.example"})
public class TransactionConfig {

	public static void main(String[] args) {
		AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(TransactionConfig.class);
		// 编程式事务测试
		// programmaticTransaction(applicationContext);

		// DeclarativeTransaction
		TxStudyService txStudyService = applicationContext.getBean(TxStudyService.class);

		DeclarativeTransaction declarativeTransaction = applicationContext.getBean(DeclarativeTransaction.class);
		declarativeTransaction.testTx();

	}

	private static void programmaticTransaction(AnnotationConfigApplicationContext applicationContext) {
		TxStudyMapper txStudyMapper = applicationContext.getBean(TxStudyMapper.class);
		txStudyMapper.transactionTemplateTest();
		txStudyMapper.tpExTest();
		txStudyMapper.tpCheckExTest();
		txStudyMapper.tpExecuteWithoutResult();
		txStudyMapper.tmTest();
	}


}


